google.load("visualization", "1", {'packages':["corechart"]});
google.load('visualization', '1', {'packages': ['piechart']});


function drawPricesChart(priceresp0) 
{
    var priceresp = eval('(' + priceresp0.responseText + ')'); 
	var pricesdata = new google.visualization.DataTable();
	pricesdata.addColumn('string', 'time');
	var nDates0 = priceresp.datesList.length;
	var nAssets = priceresp.datesList[0].assetsList.length;
	for( var asset = 0; asset < nAssets; asset++ )
    {
        pricesdata.addColumn('number', priceresp.datesList[0].assetsList[asset].name);
    }

	pricesdata.addRows(nDates0);
    for( var date = 0; date < nDates0; date++ )
    {
        pricesdata.setValue(date, 0, priceresp.datesList[date].time);
        for( var asset = 0; asset < nAssets; asset++ )
        {
            pricesdata.setValue(date, asset+1, priceresp.datesList[date].assetsList[asset].price);
        }
    }

    var priceschart = new google.visualization.LineChart(document.getElementById('priceschart_div'));
	priceschart.draw(pricesdata, {width: 600, height: 300, title: 'Prices History', curveType:'function', lineWidth:1, pointSize:0});
};

var updatePricesChart = function() 
{
    var args = { type:"get", url:"/json/getPricesHistory/", complete:drawPricesChart };
    $.ajax(args);
    return false;
};

$(document).ready( function() 
{
    updatePricesChart();
});
  
setInterval( "updatePricesChart()", 100000 );  